#ifndef _TLS_COMMON_H
#define _TLS_COMMON_H

#include <linux/in.h>
#include <linux/inet.h>
#include <linux/socket.h>
#include <net/sock.h>
#include <linux/init.h>
#include <linux/module.h>
#include "tls_connection.h"

# define TYPE_RSA                        0x01
# define TYPE_ECDSA                      0x02
# define BUFFER_SIZE                     4096
# define SSL3_RT_HANDSHAKE               22
# define SSL3_RT_APPLICATION_DATA        23
# define SSL3_VERSION                    0x0300
# define TLS1_VERSION                    0x0301
# define TLS1_1_VERSION                  0x0302
# define TLS1_2_VERSION                  0x0303
# define TLS1_3_VERSION                  0x0304
# define TLS_RECORD_HREADER_SIZE         5
# define CLIENT_HELLO_PKT_SIZE sizeof(RECORD_LAYER) + sizeof(SUB_RECORD_LAYER)
# define SERVER_HELLO_PKT_SIZE sizeof(RECORD_LAYER) + sizeof(SUB_RECORD_LAYER)
# define CLIENT_HELLO_CERT_HEADER sizeof(RECORD_LAYER) + sizeof(CERT_SUB_RECORD_LAYER)
# define SERVER_HELLO_CERT_HEADER sizeof(RECORD_LAYER) + sizeof(CERT_SUB_RECORD_LAYER)
# define KEY_SHARE_PKT_SIZE 36

int do_statem_write(TCP_CONNECTION *conn, size_t size);
int do_statem_read(TCP_CONNECTION *conn, size_t size, int flags);

static inline int ksock_send(struct socket *sock, char *buf, size_t size)
{
	struct kvec iov = { buf, size };
	struct msghdr msg = {};
    memset(&msg, 0, sizeof(msg));

	return kernel_sendmsg(sock, &msg, &iov, 1, size);
}

static inline int ksock_recv(struct socket *sock, char *buf, size_t size,
			     int flags)
{
	struct kvec iov = { buf, size };
	struct msghdr msg = { .msg_name = NULL, .msg_flags = flags };

	return kernel_recvmsg(sock, &msg, &iov, 1, size, flags);
}

#endif
